package com.vodone.v1pin.userInfo.delegate
{
	import com.vodone.v1pin.userInfo.vo.OrderItemVO;
	import com.vodone.v1pin.userInfo.vo.OrderVO;
	
	import mx.collections.ArrayCollection;

	public class OrderUtil
	{
		/**
		 * 解析用户订单列表数据
		 * */
		public static function getOrderListFromObj(obj:Object):Array
		{
			var list:Array = [];
			if(obj && obj is Array)
			{
				var arr:Array = obj as Array;
				if(arr && arr.length > 0)
				{
					for(var i:int = 0; i< arr.length ; i++)
					{
						list.push(getOrderItem(arr[i]));
					}
				}
			}
			return list;
		}
		public static function getOrderItem(obj:Object):OrderVO
		{
			var item:OrderVO = new OrderVO();
			if(obj)
			{
				if(obj.hasOwnProperty("orderNum"))
				{
					item.orderNum = obj["orderNum"];
				}
				if(obj.hasOwnProperty("createTime"))
				{
					item.createTime = obj["createTime"];
				}
				if(obj.hasOwnProperty("orderTotal"))
				{
					item.orderTotal = obj["orderTotal"];
				}
				if(obj.hasOwnProperty("orderState"))
				{
					item.orderState = obj["orderState"];
				}
				if(obj.hasOwnProperty("orderPayState"))
				{
					item.orderPayState = obj["orderPayState"];
				}
				if(obj.hasOwnProperty("orderReturnTag"))
				{
					item.orderReturnTag = obj["orderReturnTag"];
				}
				if(obj.hasOwnProperty("orderPayType"))
				{
					item.orderPayType = obj["orderPayType"];
				}
				if(obj.hasOwnProperty("orderPay"))
				{
					item.orderPay = obj["orderPay"];
				}
				if(obj.hasOwnProperty("provider"))
				{
					item.provider = obj["provider"];
				}
				if(obj.hasOwnProperty("itemList"))
				{
					item.itemList = getOrderChildList(obj["itemList"]);
				}
				
			}
			return item;
		}
		
		public static function getOrderChildList(obj:Object):ArrayCollection
		{
			var list:ArrayCollection = new ArrayCollection();
			if(obj && obj is Array)
			{
				var arr:Array = obj as Array;
				if(arr && arr.length > 0)
				{
					for(var i:int = 0; i< arr.length ; i++)
					{
						list.addItem(getOrderChildItem(arr[i]));
					}
				}
				else
				{
					list.addItem(new OrderItemVO());
				}
			}
			return list;
		}
		public static function getOrderChildItem(obj:Object):OrderItemVO
		{
			var item:OrderItemVO = new OrderItemVO();
			if(obj)
			{
				if(obj.hasOwnProperty("productID"))
				{
					item.productID = obj["productID"];
				}
				if(obj.hasOwnProperty("itemID"))
				{
					item.itemID = obj["itemID"];
				}
				if(obj.hasOwnProperty("itemPic"))
				{
					item.itemPic = obj["itemPic"];
				}
				if(obj.hasOwnProperty("itemName"))
				{
					item.itemName = obj["itemName"];
				}
				if(obj.hasOwnProperty("itemColor"))
				{
					item.itemColor = obj["itemColor"];
				}
				if(obj.hasOwnProperty("itemSize"))
				{
					item.itemSize = obj["itemSize"];
				}
				if(obj.hasOwnProperty("itemPrice"))
				{
					item.itemPrice = obj["itemPrice"];
				}
				if(obj.hasOwnProperty("discount"))
				{
					item.discount = obj["discount"];
				}
				if(obj.hasOwnProperty("itemCount"))
				{
					item.itemCount = obj["itemCount"];
				}
			}
			return item;
		}
		
		public static function getOrderState(state:String , payState:int):String
		{
			if(state == "0" || state == "1")
			{
				/*case "0":return "未审核" ; break;
				case "1":return "审核通过";break;*/
				return payState == 0 ? "待付款" : "已付款";
			}
			switch(state)
			{
				case "2":return "配货中";break;
				case "3":return "已取消";break;
				case "4":return "发货中";break;
				case "7":return "交易完成";break;
				case "-9":return "待审核";break;
				case "13":return "退货办理中";break;
				case "14":return "退货已完成	";break;
			}
			return "";
		}
	}
}